<template>
	<view>
		<cu-custom bgColor="bg-gradual-fff" isBack="true">
			<block slot="content">余额明细</block> 
		</cu-custom>
		<u-loading-page :loading="true" loading-text="loading..." v-if="showLoading"></u-loading-page>
		<view v-show="!showLoading">
			<view class="viewbox"></view>
			<view class="index_b_d_aaa">
				<u-tabs
					ref="tabs" 
					:current="current" 
					@click="tabsChange" 
					lineColor="#E71102"
					:activeStyle="{
							fontSize: '28rpx',
							fontFamily: 'PingFang SC',
							fontWeight: '800',
							color: '#E71102'
							}"
					:inactiveStyle="{
							fontSize: '28rpx',
							fontFamily: 'PingFang SC',
							color: '#333333'
							}"
					itemStyle="padding-left:20rpx; padding-right:20rpx; height: 80rpx;"
					:list="order_type" 
					:is-scroll="false"
					>
				</u-tabs>
			</view>
			<view class="user_withdraw_code" v-if="withdrawList.length>0">
				<view v-if="current==1">
					<view class="user_withdraw_code_a" v-for="(item, index) in withdrawList" :key="index">
						<view class="user_withdraw_code_a_a">
							<view class="user_withdraw_code_a_a_a">{{item.desc}}</view>
							<view class="user_withdraw_code_a_a_b">¥<span>{{item.total}}</span></view>
						</view>
						<view class="user_withdraw_code_a_b">
							<view class="user_withdraw_code_a_b_a">{{item.create_time}}</view>
						</view>
					</view>
				</view>
				<view v-else>
					<view class="user_withdraw_code_a" v-for="(item, index) in withdrawList" :key="index">
						<view class="user_withdraw_code_a_a">
							<view class="user_withdraw_code_a_a_a">{{item.remark}}</view>
							<view class="user_withdraw_code_a_a_b">{{item.change_amount}}</view>
						</view>
						<view class="user_withdraw_code_a_b">
							<view class="user_withdraw_code_a_b_a">{{item.create_time}}</view>
							<view class="user_withdraw_code_a_b_b">明细余额{{item.left_amount}}</view>
						</view>
					</view>
				</view>
			</view>
			<loading-footer :status="status" :slot-empty="true">
				<view slot="empty" class="column-center" style="padding-top: 200rpx">
					<image class="img-null" src="/static/goods_null.png"></image>
					<text class="lighter">暂无明细记录</text>
				</view>
			</loading-footer>
		</view>
	</view>
	
</template>
<script>
import request from '@/common/request.js';	
import {
	loadingType
} from '@/utils/type';
export default {
	data() {
		return {
			showLoading:true,
			uid:0,
			baseUrl_img:request.baseUrl_img,
			withdrawList:[],
			status: loadingType.LOADING,
			source_type:0,
			page: 1,
			limit:8,
			current:0,
			order_type: [
				{
					name:'全部'
				},
				{
					name:'充值'
				},
				{
					name:'支出'
				},
				{
					name:'收入'
				}
			],
		}
	},
	onLoad(options) {
		
	},
	onShow(){
		this.uid=uni.getStorageSync('uid');
		this.onRefresh();
	},
	onReachBottom: function() {
		this.getWithdrawFun();
	},
	mounted() {
		//this.home_post();
	},
	methods: {
		tabsChange(e){
			this.current = e.index;
			this.onRefresh();
		},
		onRefresh() {
			this.page = 1
			this.withdrawList = []
			this.status = loadingType.LOADING;
			this.getWithdrawFun();
		},
		async getWithdrawFun() {
			let {
				page,
				limit,
				withdrawList,
				status
			} = this;
			if (status == loadingType.FINISHED) return;
			const paramsList = {
				page: page,
				limit:limit,
				uid:this.uid
			}
			let url='u-AccountLogList';
			if(this.current==0){
				paramsList.source_type=1
			}
			if(this.current==1){
				url='r-rechargeRecord'
			}
			if(this.current==2){
				paramsList.source_type=1
				paramsList.type=2
			}
			if(this.current==3){
				paramsList.source_type=1
				paramsList.type=1
			}
			let optsList = {
				url:url,
				method: 'get'
			};
			request.httpTokenRequest(optsList, paramsList).then(res => {
				if(res.data.code == 200){
					if(page == 1) withdrawList = []
					let {
						list,
						more
					} = res.data.data
					this.withdrawList.push(...list)
					this.page = ++page
					if (!more) {
						this.status = loadingType.FINISHED
					}
					if (this.withdrawList.length <= 0) {
						this.status = loadingType.EMPTY
					}
				} else {
					this.status = loadingType.ERROR
				}
				this.showLoading=false;
			});
		}
	}
}
</script>

<style  lang="scss" scoped>
	.user_withdraw_code{
		overflow: hidden;
	}
	.user_withdraw_code_a{
		width: 702rpx;
		height:auto;
		background: #FFFFFF;
		border-radius: 20rpx;
		margin: auto;
		margin-top: 20rpx;
		overflow: hidden;
		padding: 33rpx 28rpx;
	}
	.user_withdraw_code_a_a{
		overflow: hidden;
	}
	.user_withdraw_code_a_a_a{
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #333333;
		float: left;
	}
	.user_withdraw_code_a_a_b{
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color:#DA0909;
		float:right;
	}
	.user_withdraw_code_a_b{
		overflow: hidden;
		margin-top: 20rpx;
	}
	.user_withdraw_code_a_b_a{
		font-size: 26rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #666666;
		float: left;
	}
	.user_withdraw_code_a_b_b{
		font-size: 26rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color:#BABABA;
		float:right;
	}
	.user_withdraw_code_a_c{
		margin-top: 20rpx;
		font-size: 26rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color:#FF3F4B;
	}
	.user_withdraw_code_a_c{
		height: 175rpx;
		width: 100%;
		overflow: hidden;
	}
	.user_withdraw_code_a_c_a{
		width: 175rpx;
		height: 175rpx;
	}
</style>
